<!-- 添加学生 -->
<template>
  <section class="add">
    <el-form ref="form" :model="form" label-width="80px">
     <el-form-item label="用户名">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password"></el-input>
        </el-form-item>
		<el-form-item label="身份" prop="status">
                <el-select v-model="form.status" placeholder="请输入身份">
                  <el-option label="租户" value=1></el-option>
                  <el-option label="用户" value=2></el-option>
                  <el-option label="答者" value=3></el-option>
                </el-select>
              </el-form-item>
        <el-form-item label="租费">
          <el-input v-model="form.cost"></el-input>
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="form.phone"></el-input>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="form.email"></el-input>
        </el-form-item>
     <el-form-item label="群组">
          <el-input v-model="form.group_id"></el-input>
        </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit()">立即创建</el-button>
        <el-button type="text" @click="cancel()">取消</el-button>
      </el-form-item>
    </el-form>
  </section>
</template>

<script>
export default {
  data() {
    return {
      form: { //表单数据初始化
        username: null,
        password: null,
        status: null,
        cost: null,
        phone: null,
        email: null,
        group_id: null,
      }
    };
  },
  methods: {
    onSubmit() {
		//数据提交
		console.log(this.form.status);
	if ((this.form.status-1) == this.$cookies.get("cstatus")) {
		this.$axios({
		  url: `/api/register`,
		  method: 'post',
		  data: {
		    ...this.form
		  }
		 }).then(res => {
		   if(res.data.code == 200) {
		     this.$message({
		       message: '数据添加成功',
		       type: 'success'
		     })
		     this.$router.push({path: '/studentManage'})
		   }
		 })
	} else{
		this.$alert("不能添加与身份不符的用户")
	}  
    },
    cancel() { //取消按钮
      this.form = {}
    },

  }
};
</script>
<style lang="less" scoped>
.add {
  padding: 0px 40px;
  width: 400px;
}
</style>

